package com.github.chain.admin.server.controller;

import com.github.chain.admin.common.domain.User;
import com.github.chain.admin.common.request.UserRequest;
import com.github.chain.admin.server.service.UserService;
import com.github.framework.core.Result;
import com.github.framework.core.page.DataPage;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

@RestController
public class UserController {


    @Resource
    private UserService userService;

    @GetMapping("/findUserByUserName")
    Result<User> findUserByUserName(@RequestParam("userName") String userName){
        return userService.findUserByUserName(userName);
    }

    @PostMapping("/findUserByPage")
    Result<DataPage<User>> findUserByPage(@RequestBody UserRequest userRequest){
        return userService.findUserByPage(userRequest);
    }

    @GetMapping("/findUserById/{id}")
    Result<User> findUserById(@PathVariable Long id){
        return userService.findUserById(id);
    }

    @PostMapping("/saveUser")
    Result<Integer> saveUser(@RequestBody UserRequest userRequest){
        return userService.saveUser(userRequest);
    }

    @PostMapping("/updateUser")
    Result<Integer> updateUser(@RequestBody UserRequest userRequest){
        return userService.updateUser(userRequest);
    }

    @GetMapping("/deleteUserById/{id}")
    Result<Integer> deleteUserById(@PathVariable("id") Long id){
        return userService.deleteUserById(id);
    }

    @PostMapping("/enableUserStatus")
    Result<Integer> enableUserStatus(@RequestBody List<Long> ids){
        return userService.enableUserStatus(ids);
    }

    @PostMapping("/disableUserStatus")
    Result<Integer> disableUserStatus(@RequestBody List<Long> ids){
        return userService.disableUserStatus(ids);
    }

    @PostMapping("/modifyUserPassword")
    Result<Integer> modifyUserPassword(@RequestBody UserRequest userRequest){
        return userService.modifyUserPassword(userRequest);
    }

    @GetMapping("/roleAssignmentById/{id}")
    Result<User> roleAssignmentById(@PathVariable("id") Long id){
        return userService.roleAssignmentById(id);
    }

    @PostMapping("/authUserRole")
    Result<Integer> authUserRole(@RequestBody UserRequest userRequest){
        return userService.authUserRole(userRequest);
    }
}
